package megalopolis.server;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.net.Socket;

import megalopolis.model.Man;
import megalopolis.net.Request;
import megalopolis.net.Response;

/**
 * User: Kirill
* Date: 19.03.2008
*/
public class Player {

	public ObjectInputStream in;

	public ObjectOutputStream out;

	public boolean logined;

	public Man man;

	public Player(Socket socket) throws IOException {
		out = new ObjectOutputStream(socket.getOutputStream());
		in = new ObjectInputStream(socket.getInputStream());
	}

	public Man getMan() {
		return man;
	}

	public void setMan(Man man) {
		this.man = man;
	}

	public Request getNextRequest() throws IOException {
		try {
			return (Request) in.readObject();
		} catch (ClassNotFoundException e) {
			throw new IOException(e.toString());
		}
	}

	public void sendResponse(Response response) {
		try {
			out.reset();
			out.writeObject(response);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
